@extends('layouts._main')

@section('title','完善注册信息')

@section('css')
    <style>
        body{
            background-color: #ececec;
        }

        .nav_bar>.nav_back {
            background: url(/images/version1/icon_bar_back.png) no-repeat;
            background-size: 20px 20px;
            display: inline-block;
            float: left;
        }
        .am-form{

            margin-top: 1px;
        }
        .form_input_body{
            background-color: #fff;
        }
        .nav_bar{
            background-color: #fff;
            box-shadow: 0px 2px 12px 1px #ddd;
            padding: 10px 15px;
            text-align: center;
        }

        .weui-label {
            display: block;
            width: 90px;
            word-wrap: break-word;
            word-break: break-all;
        }
        .weui-cell .weui-ft:after {
            content: " ";
            display: inline-block;
            height: 6px;
            width: 6px;
            border-width: 2px 2px 0 0;
            border-color: #d79705;
            border-style: solid;
            -webkit-transform: matrix(0.71, 0.71, -0.71, 0.71, 0, 0);
            transform: matrix(0.71, 0.71, -0.71, 0.71, 0, 0);
            position: relative;
            top: -2px;
            position: absolute;
            top: 50%;
            right: 15px;
            margin-top: -4px;
        }
        .weui-btn_primary {
            background-color: #d79705;
        }
        .weui-cell:before {
            content: " ";
            position: absolute;
            left: 0;
            bottom: 0;
            right: 0;
            height: 1px;
            border-bottom: 1px solid #e5e5e5;
            color: #e5e5e5;
            -webkit-transform-origin: 0 0;
            transform-origin: 0 0;
            -webkit-transform: scaleY(0.5);
            transform: scaleY(0.5);
            left: 15px;
            z-index: 2;
        }
    </style>
@endsection

@section('container')
    {{--主色调：#d79705;渐变色调浅色：#dec07a--}}
    <div class="body">
        {{--<div class="nav_bar">
            编辑信息<div class="nav_back"></div>
        </div>--}}
        {{--表单--}}
        <form class="am-form am-form-horizontal" id="form" action="{{ url('/user/edit') }}" method="post" >
            {{ csrf_field()}}
            <div class="form_input_body">

                <div class="weui-cell" style="margin-top: 0px;padding: 0px"></div>
                {{--姓名--}}
                @if(in_array('name',$new_fields))
                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label for="" class="weui-label">姓名</label></div>
                        <div class="weui-cell__bd">
                            <input class="weui-input" required type="text" name="member_optional_name" value="" maxlength="80" placeholder="请填写姓名">
                        </div>
                    </div>
                @endif
                {{--出生日期--}}
                @if(in_array('birthday',$new_fields))
                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label for="" class="weui-label">出生日期</label></div>
                        <div class="weui-cell__bd weui-ft showDatePicker">
                            <span>未知</span>
                            <input class="weui-input" required type="hidden" name="member_optional_birthday" value="" placeholder="出生日期">
                        </div>
                    </div>
                @endif
                {{--性别--}}
                @if(in_array('gender',$new_fields))

                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label for="" class="weui-label">性别</label></div>
                        <div class="weui-cell__bd weui-ft showSexPicker">
                            <span>未知</span>
                            <input class="weui-input" required type="hidden" name="member_optional_gender" readonly value="">
                        </div>
                    </div>
                @endif
                {{--身份证号--}}
                @if(in_array('identity_code',$new_fields))

                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label for="" class="weui-label">身份证号</label></div>
                        <div class="weui-cell__bd">
                            <input class="weui-input" required type="number" name="member_optional_identity_code" maxlength="30" value="" placeholder="请填写身份证号">
                        </div>
                    </div>
                @endif
                {{--年收入--}}
                @if(in_array('annual_income',$new_fields))

                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label for="" class="weui-label">年收入</label></div>
                        <div class="weui-cell__bd">
                            <input class="weui-input" required type="number" name="member_optional_annual_income" value="" placeholder="请填写年收入">
                        </div>
                    </div>
                @endif
                {{--婚姻状况--}}
                @if(in_array('marriage',$new_fields))

                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label for="" class="weui-label">婚姻状况</label></div>
                        <div class="weui-cell__bd weui-ft showPicker">
                            <span>未知</span>
                            <input class="weui-input" required type="hidden" name="member_optional_marriage" value="" placeholder="">
                        </div>
                    </div>
                @endif
                {{--子女名字--}}
                @if(in_array('child_name',$new_fields))

                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label for="" class="weui-label">子女名字</label></div>
                        <div class="weui-cell__bd">
                            <input class="weui-input" required type="email" value="" name="member_optional_child_name" maxlength="80" placeholder="请填写子女名字">
                        </div>
                    </div>
                @endif
                {{--子女性别--}}
                @if(in_array('child_sex',$new_fields))

                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label for="" class="weui-label">子女性别</label></div>
                        <div class="weui-cell__bd weui-ft showSexPicker">
                            <span>未知</span>
                            <input class="weui-input" required type="hidden" value="" name="member_optional_child_sex">
                        </div>
                    </div>
                @endif
                {{--子女生日--}}
                @if(in_array('child_birthday',$new_fields))

                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label for="" class="weui-label">子女生日</label></div>
                        <div class="weui-cell__bd weui-ft showDatePicker">
                            <span>未知</span>
                            <input class="weui-input" required type="hidden" value="" name="member_optional_child_birthday">
                        </div>
                    </div>
                @endif
                {{--喜好--}}
                @if(in_array('favor',$new_fields))

                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label for="" class="weui-label">喜好</label></div>
                        <div class="weui-cell__bd">
                            <input class="weui-input" required type="text" maxlength="100" value="" placeholder="请输入喜好" name="member_optional_favor">
                        </div>
                    </div>
                @endif
                {{--特殊需求--}}
                @if(in_array('demands',$new_fields))

                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label for="" class="weui-label">特殊需求</label></div>

                        <div class="weui-cell__bd">
                            <div class="weui-cells weui-cells_form">
                                <div class="weui-cell">
                                    <div class="weui-cell__bd">
                                        <textarea class="weui-textarea" maxlength="200" name="member_optional_demands" placeholder="请输入特殊需求" rows="3"></textarea>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                @endif
            </div>


            {{--提交按钮--}}
            <div class="weui-btn-area" style="margin-top: 10%">
                <button class="weui-btn weui-btn_primary submit" href="javascript:" >完  成</button>
            </div>

        </form>
    </div>
@endsection

@section('js')


    <script>
        var new_fields = JSON.parse('{!! json_encode($new_fields) !!}');

        // 生日
        $('.showDatePicker').click(function(event) {
            var _this = this;
            weui.datePicker({
                start: new Date().getFullYear()-110,
                end: new Date(),
                defaultValue: [new Date().getFullYear(), new Date().getMonth()+1, new Date().getDate()],
                onConfirm: function(result){
                    console.log($(_this).find('input'));
                    $(_this).find('span').text(result[0].value+'-'+result[1].value+'-'+result[2].value);
                    $(_this).find('input').val(result[0].value+'-'+result[1].value+'-'+result[2].value);
                },
            });
        });

        // 否婚
        $('.showPicker').on('click', function () {
            var _this=this;
            weui.picker([{
                label: '已婚',
                value: 1
            }, {
                label: '未婚',
                value: 2
            }], {
                onConfirm: function (result) {

                    $(_this).find('span').text(result[0].label);
                    $(_this).find('input').val(result[0].value);

                }
            });
        });

        // 性别
        $('.showSexPicker').on('click', function () {
            var _this=this;
            weui.picker([{
                label: '男',
                value: 1
            }, {
                label: '女',
                value: 2
            }], {
                onConfirm: function (result) {
                    $(_this).find('span').text(result[0].label);
                    $(_this).find('input').val(result[0].value);
                }
            });
        });

        //后台验证错误
        if("{{ $errors->has('member_optional_name') }}") showMsg("{{ $errors->first('name') }}");
        if("{{ $errors->has('member_optional_telephone') }}") showMsg("{{ $errors->first('telephone') }}");
        if("{{ $errors->has('member_optional_birthday') }}") showMsg("{{ $errors->first('birthday') }}");
        if("{{ $errors->has('member_optional_gender') }}") showMsg("{{ $errors->first('gender') }}");
        if("{{ $errors->has('member_optional_identity_code') }}") showMsg("{{ $errors->first('identity_code') }}");
        if("{{ $errors->has('member_optional_annual_income') }}") showMsg("{{ $errors->first('annual_income') }}");
        if("{{ $errors->has('member_optional_marriage') }}") showMsg("{{ $errors->first('marriage') }}");
        if("{{ $errors->has('member_optional_child_sex') }}") showMsg("{{ $errors->first('child_sex') }}");
        if("{{ $errors->has('member_optional_child_birthday') }}") showMsg("{{ $errors->first('child_birthday') }}");
        if("{{ $errors->has('member_optional_child_name') }}") showMsg("{{ $errors->first('child_name') }}");
        if("{{ $errors->has('member_optional_favor') }}") showMsg("{{ $errors->first('favor') }}");
        if("{{ $errors->has('member_optional_demands') }}") showMsg("{{ $errors->first('demands') }}");


        //提交
        $('.submit').click(function () {
            if($(this).hasClass('loadding')){
                return false;
            }
            $(this).addClass('loadding');
            console.log(new_fields);
            if(new_fields.indexOf('name')>=0){
                var name = $('input[name=member_optional_name]').val();

                if(name=='') {
                    showMsg('姓名不能为空');
                    $(this).removeClass('loadding');
                    return false;
                }
            }
            if(new_fields.indexOf('birthday')>=0){
                var birthday = $('input[name=member_optional_birthday]').val();

                if(!birthday) {
                    showMsg('生日不能为空');
                    $(this).removeClass('loadding');
                    return false;
                }

            }

            if(new_fields.indexOf('gender')>=0){
                var gender = $('input[name=member_optional_gender]').val();
                if(!gender) {
                    showMsg('性别不能为空');
                    $(this).removeClass('loadding');
                    return false;
                }

            }
            if(new_fields.indexOf('identity_code')>=0){
                var identity_code = $('input[name=member_optional_identity_code]').val();

                if(!validateIdNumber(identity_code) || !identity_code) {
                    showMsg('请填写正确的身份证号');
                    $(this).removeClass('loadding');
                    return false;
                }
            }
            if(new_fields.indexOf('annual_income')>=0){
                var annual_income = $('input[name=member_optional_annual_income]').val();

                if(!annual_income) {
                    showMsg('年收入不能为空');
                    $(this).removeClass('loadding');
                    return false;
                }
            }
            if(new_fields.indexOf('marriage')>=0){
                var marriage = $('input[name=member_optional_marriage]').val();
                if(!marriage) {
                    showMsg('是否结婚不能为空');
                    $(this).removeClass('loadding');
                    return false;
                }
            }
            if(new_fields.indexOf('child_sex')>=0){
                var child_sex = $('input[name=member_optional_child_sex]').val();
                if(!child_sex) {
                    showMsg('子女性别不能为空');
                    $(this).removeClass('loadding');
                    return false;
                }
            }

            if(new_fields.indexOf('child_birthday')>=0){
                var child_birthday = $('input[name=member_optional_child_birthday]').val();
                console.log();
                if(!child_birthday) {
                    showMsg('子女生日不能为空');
                    $(this).removeClass('loadding');
                    return false;
                }
            }

            if(new_fields.indexOf('child_name')>=0){
                var child_name = $('input[name=member_optional_child_name]').val();
                if(!child_name) {
                    showMsg('子女姓名不能为空');
                    $(this).removeClass('loadding');
                    return false;
                }
            }

            if(new_fields.indexOf('favor')>=0){
                var favor = $('input[name=member_optional_favor]').val();
                if(!favor) {
                    showMsg('喜好不能为空');
                    $(this).removeClass('loadding');
                    return false;
                }
            }

            if(new_fields.indexOf('demands')>=0){
                var demands = $('input[name=member_optional_demands]').val();
                if(!demands) {
                    showMsg('特殊需求不能为空');
                    $(this).removeClass('loadding');
                    return false;
                }
            }

            $('#form').submit();

            return false;
        });

    </script>
@endsection